<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>向字符串添加空格</title>
</head>

<body>
  <script>
    var addSpaces = function (s, spaces) {
      const res = []
      res.push(s.substring(0, spaces[0]))
      for (let i = 0; i < spaces.length; i++) {
        res.push(s.substring(spaces[i], spaces[i + 1]))
      }
      return res.join(" ")
    };
    console.log(addSpaces('EnjoyYourCoffee', [5, 9]))
  </script>
</body>

</html>